<template>
	<view class="content">
		<uni-forms ref="form" :value="formData" :rules="rules">
			<uni-forms-item name="pwd">
				<uni-easyinput type="password" class="easyinput" :inputBorder="false" v-model="formData.oldpwd"
					placeholder="请输入旧密码"></uni-easyinput>
			</uni-forms-item>
			<uni-forms-item name="pwd">
				<uni-easyinput type="password" class="easyinput" :inputBorder="false" v-model="formData.pwd"
					placeholder="请输入新密码"></uni-easyinput>
			</uni-forms-item>
			<uni-forms-item name="pwd2">
				<uni-easyinput type="password" class="easyinput" :inputBorder="false" v-model="formData.pwd2"
					placeholder="请确认密码"></uni-easyinput>
			</uni-forms-item>
			<button class="send-btn-box" type="primary" @click="submit">完成</button>
		</uni-forms>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				lock:false,
				formData: {
					"oldpwd": "",
					'pwd': '',
					'pwd2': ''
				},
				rules: {
					pwd: {
						rules: [{
								required: true,
								errorMessage:"请输入新密码",
							},
							{
								pattern: /^.{6,18}$/,
								errorMessage: "密码为6 - 18位",
							}
						]
					},
					pwd2: {
						rules: [{
								required: true,
								errorMessage:"请确认密码",
							},
							{
								pattern: /^.{6,18}$/,
								errorMessage: "密码为6 - 18位",
							},
							{
								validateFunction: function(rule, value, data, callback) {
									// console.log(value);
									if (value != data.pwd) {
										callback('两次输入密码不一致')
									};
									return true
								}
							}
						]
					}
				}
			}
		},
		computed: {
		},
		onLoad(event) {		 
		},
		methods: {
			submit() {
				this.$refs.form.validate()
					.then(res => {
						 this.$http.put('/system/user/updatePwd?oldPassword='+this.formData.oldpwd+'&newPassword='+this.formData.pwd+'').then(res => {
						 	uni.showToast({
						 		title:"更新成功",
						 		icon: 'none'
						 	});
						 });
					})
			}
		}
	}
</script>

<style>
	@import url("login-page.css");

	.content{
		padding-top: 36rpx;
	}
</style>
